package com.ruoyi.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.entity.dto.WechatBindParam;
import com.ruoyi.common.service.IWechatService;
import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 微信绑定控制器
 * 处理用户微信绑定、解绑及状态查询相关请求
 */
@RestController
@RequestMapping("/api/user/wechat")
@Api(tags = "微信绑定接口")
public class WechatController {

    @Autowired
    private IWechatService wechatService;

    /**
     * 微信绑定接口
     * @param code 微信授权code
     * @return 绑定结果
     */
    @PostMapping("/bind")
    @ApiOperation("微信绑定")
    public AjaxResult bindWechat(@RequestBody WechatBindParam code) {
        Long userId = SecurityUtils.getUserId();
        return wechatService.bindWechat(userId, code.getCode());
    }

    /**
     * 微信解绑接口
     * @return 解绑结果
     */
    @PostMapping("/unbind")
    @ApiOperation("微信解绑")
    public AjaxResult unbindWechat(HttpServletRequest request) {
        Long userId = SecurityUtils.getUserId();
        return wechatService.unbindWechat(userId);
    }

    /**
     * 查询微信绑定状态
     * @return 绑定状态信息
     */
    @GetMapping("/status")
    @ApiOperation("查询微信绑定状态")
    public AjaxResult getWechatBindStatus(HttpServletRequest request) {
        return wechatService.getWechatBindStatus();
    }


}
    